package com.jdz.gxq.info.admin.landinfo.action;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import org.apache.struts.action.ActionForm;
import org.apache.struts.action.ActionForward;
import org.apache.struts.action.ActionMapping;

import com.jdz.gxq.info.admin.landinfo.bo.Landinfo;
import com.jdz.gxq.info.admin.landinfo.form.LandinfoListForm;
import com.jdz.gxq.info.admin.landinfo.service.LandinfoService;
import com.jdz.gxq.info.common.action.CommonAction;
import com.jdz.gxq.info.common.bo.PageBean;

public class LandinfoListAction extends CommonAction {

	private LandinfoService landinfoService = null;

	public ActionForward doExecute(ActionMapping mapping, ActionForm form,
			HttpServletRequest request, HttpServletResponse response)
			throws java.lang.Exception {

		LandinfoListForm landinfoListForm = (LandinfoListForm) form;

		String projectName = landinfoListForm.getEnterpriseName();

		int totalCount = landinfoService.getLandinfosCount(projectName);

		int currentPage = landinfoListForm.getPageIndex();

		PageBean pageBean = new PageBean(totalCount, currentPage);

		landinfoListForm.setPageIndex(pageBean.getCurrentPage());

		Map<String, Object> params = new HashMap<String, Object>();

		// 分页用
		params.put("startRow", pageBean.getPageStartRow() - 1);
		params.put("rowSize", pageBean.getPageSize());
		params.put("projectName", projectName);

		List<Landinfo> landinfoList = landinfoService.getLandinfos(params);

		request.setAttribute("landinfoList", landinfoList);
		request.setAttribute("pageBean", pageBean);

		return mapping.findForward("success");
	}

	public void setLandinfoService(LandinfoService landinfoService) {
		this.landinfoService = landinfoService;
	}
}
